package com.growthgate.bootcommon.service.impl;

import com.growthgate.bootcommon.common.base.BaseServiceImpl;
import com.growthgate.bootcommon.entity.User;
import com.growthgate.bootcommon.repository.UserRepository;
import com.growthgate.bootcommon.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * UserServiceImpl
 *
 * @author GrowthGate
 * @date 2019/12/11
 */
@Service
public class UserServiceImpl extends BaseServiceImpl<User, UserRepository> implements UserService {

    @Autowired
    public UserServiceImpl(UserRepository repository) {
        super(repository);
    }

    @Override
    protected ExampleMatcher getExampleMatcher() {
        return ExampleMatcher.matching()
                .withMatcher("id", ExampleMatcher.GenericPropertyMatcher::exact)
                .withMatcher("username", ExampleMatcher.GenericPropertyMatcher::contains)
                .withMatcher("nickname", ExampleMatcher.GenericPropertyMatcher::contains)
                .withMatcher("sex", ExampleMatcher.GenericPropertyMatcher::exact)
                .withMatcher("age", ExampleMatcher.GenericPropertyMatcher::exact);
    }

    @Override
    public User findUserByUsername(String username) {
        return repository.findUserByUsername(username);
    }

    @Override
    public User getUserByUsername(String username) {
        return repository.getUserByUsername(username);
    }

    @Override
    public List<User> findByNicknameContaining(String str) {
        return repository.findByNicknameContaining(str);
    }

}